package com.dingwen.pro.demo03;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * 代理调用处理程序
 *
 * @author dingwen
 * @date 2021/10/06
 */
public class ProxyInvocationHandler implements InvocationHandler {
    /**
     * 抽象接口
     */
    private Rent rent;

    public void setRent(Rent rent) {
        this.rent = rent;
    }

    /**
     * 获得代理对象
     *
     * @return {@link Object}
     */
    public Object getProxy(){
        return Proxy.newProxyInstance(this.getClass().getClassLoader(),rent.getClass().getInterfaces(),this);
    }
    
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        see();
        Object result = method.invoke(rent, args);
        sign();
        return result;
    }

    public void see(){
        System.out.println("看房");
    }
    public void sign(){
        System.out.println("签合同");
    }
}
